package com.health.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.health.model.BloodPressure;
import com.health.model.BloodSugar;
import com.health.model.User;

public class PKGenerator
{
	private static String			userId		= "";
	private static String			pressureId	= "";
	private static String			sugarId		= "";
	private static SimpleDateFormat	sdf			= new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

	/**
	 * userPK(id) the generation rule of user's id email_name_birthdate
	 */
	public static String userIdGenerator(User user)
	{
		Calendar c = Calendar.getInstance();
		c.setTime(user.getRegistertime());
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH) + 1;// Calendar month+1
		int day = c.get(Calendar.DATE);
		int hour = c.get(Calendar.HOUR);
		int min = c.get(Calendar.MINUTE);
		int sec = c.get(Calendar.SECOND);
		// int MI = c.get(Calendar.MILLISECOND);

		// String genderText = "" ;
		// if(user.getGender() == 0) {
		// genderText = "male";
		// } else if(user.getGender() == 1) {
		// genderText = "female";
		// }
		// Random random = new Random();
		// userId = year + "-" + month + "-" + day + "_" +
		// hour + ":" + min + ":" + sec + "_" +
		// genderText + "_" +
		// name +
		// random.nextInt(9);
		userId = user.getEmail() + "_" + user.getName() + "_" + year + "-"
				+ month + "-" + day + "_" + hour + ":" + min + ":" + sec;
		return userId;
	}

	/**
	 * bloodpressure's id generation rule time_userid
	 */
	public static String bloodPressureIdGenerator(BloodPressure p)
	{
		Date examTime = p.getExamTime();
		// BloodPressureServiceImpl service = new BloodPressureServiceImpl();
		String userId = p.getUserId();
		pressureId = sdf.format(examTime) + "_" + userId;
		return pressureId;
	}

	/**
	 * bloodsugar's id generation rule time_userid
	 */
	public static String bloodSugarIdGenerator(BloodSugar s)
	{
		Date examTime = s.getExamTime();
		// BloodPressureServiceImpl service = new BloodPressureServiceImpl();
		String userId = s.getUserId();
		sugarId = sdf.format(examTime) + "_" + userId;
		return sugarId;
	}
}
